home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / Property 2.1 / property.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-30  |  2.6 KB  |  106 lines  |  [TEXT/CWIE]

  1. /*
  2.     property is © 1996 Boxes Objects Links Design Pty Ltd.  All Rights Reserved. 
  3.     You use this software at your own risk, etc. Permission is given to Timothy C.
  4.     Delaney to use property. Permission is given for all others to use property if
  5.     acknowledgement of this copyright is given in publically-released software.
  6.     Acknowledgement should consist of a statement equivalent to "Sections of this
  7.     program are © Boxes Objects Links Design Pty Ltd", visible in an "About..." box
  8.     or splash screen.
  9.                                                                                         */
  10.  
  11. #ifndef    _H_property
  12. #define    _H_property
  13.  
  14. #include <bool.h>
  15.  
  16. enum EPropertyAccess
  17. {
  18.     propertyAccess_ReadOnly        = 'PAR0',
  19.     propertyAccess_WriteOnly    = 'PA0W',
  20.     propertyAccess_ReadWrite    = 'PARW'
  21. };
  22.  
  23. template <EPropertyAccess access, class T>
  24. class property
  25. {
  26.     public:
  27.  
  28.                             property (void * const    theObject,
  29.                                       T                &field                                    );
  30.  
  31.                             property (void * const    theObject,
  32.                                       void            (*getFunc) (void * const, T &    )        );
  33.  
  34.                             property (void * const    theObject,
  35.                                       void            (*setFunc) (void * const, const T &    )    );
  36.  
  37.                             property (void * const    theObject,
  38.                                       T                &getField,
  39.                                       T                &setField                                );
  40.  
  41.                             property (void * const    theObject,
  42.                                       void            (*getFunc) (void * const, T &    ),
  43.                                       T                &setField                                );
  44.  
  45.                             property (void * const    theObject,
  46.                                       T                &getField,
  47.                                       void            (*setFunc) (void * const, const T &    )    );
  48.  
  49.                             property (void * const    theObject,
  50.                                       void            (*getFunc) (void * const, T &        ),
  51.                                       void            (*setFunc) (void * const, const T &    )    );
  52.  
  53.         virtual                ~property (void                                                    );
  54.  
  55.                             operator T (void                                                );
  56.         property &            operator= (const T    &newValue                                    );
  57.         property &            operator= (property<access, T>    newProperty                        );
  58.  
  59.         property &            operator+= (const T    &newValue                                    );
  60.         property &            operator-= (const T    &newValue                                    );
  61.         property &            operator*= (const T    &newValue                                    );
  62.         property &            operator/= (const T    &newValue                                    );
  63.  
  64.     private:
  65.  
  66.         enum EInternalAccess
  67.         {
  68.             internalAccess_None,
  69.             internalAccess_Field,
  70.             internalAccess_Func
  71.         };
  72.  
  73.         union UPropertyGet
  74.         {
  75.             T        *mGetField;
  76.             void    (*mGetFunc) (void *, T &    );
  77.         };
  78.  
  79.         union UPropertySet
  80.         {
  81.             T        *mSetField;
  82.             void    (*mSetFunc) (void *, const T &    );
  83.         };
  84.  
  85.         void * const        mObject;
  86.  
  87.         EInternalAccess        mGetAccess,
  88.                             mSetAccess;
  89.  
  90.         UPropertyGet        mGet;
  91.         UPropertySet        mSet;
  92.  
  93.         bool                Readable (void                        );
  94.         bool                Writeable (void                        );
  95.  
  96.         bool                ReadFunc (void                        );
  97.         bool                WriteFunc (void                        );
  98.  
  99.         void                ThrowAccess_(void                    )    throw (EPropertyAccess);
  100.         void                MatchAccess_(void                    )    throw (EPropertyAccess);
  101. };
  102.  
  103. #include "property.cp"
  104.  
  105. #endif
  106.